package com.dfec.water.dao;

import com.dfec.framework.mybatis.core.mapper.BaseMapperX;
import com.dfec.framework.mybatis.core.page.PageParam;
import com.dfec.framework.mybatis.core.page.PageUtils;
import com.dfec.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.dfec.water.entity.YdbDeviceZsyEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 蒸渗仪Dao接口
 *
 * @author df
 * @date Fri Jan 10 15:02:12 CST 2025
 */
@Mapper
public interface YdbDeviceZsyDao extends BaseMapperX<YdbDeviceZsyEntity> {

    /**
     * description:分页查询
     *
     * @param pageParam 分页参数
     * @return
     * @author trg
     * @date 2023/6/27 15:56
     */
    default PageUtils selectPage(PageParam<YdbDeviceZsyEntity> pageParam) {
        YdbDeviceZsyEntity entity = pageParam.getEntity() == null ? new YdbDeviceZsyEntity() : pageParam.getEntity();
        return this.selectPage(pageParam, dealParams(entity));
    }


    /**
     * 不带分页查询
     *
     * @param ydbDeviceTypeEntity
     * @return
     */
    default List<YdbDeviceZsyEntity> selectAll(YdbDeviceZsyEntity ydbDeviceTypeEntity) {
        return this.selectList(dealParams(ydbDeviceTypeEntity));
    }

    /**
     * description:查询条件拼接
     *
     * @param entity 参数
     * @return
     * @author trg
     * @date 2023/6/27 15:56
     */
    public default LambdaQueryWrapperX<YdbDeviceZsyEntity> dealParams(YdbDeviceZsyEntity entity) {
        return new LambdaQueryWrapperX<YdbDeviceZsyEntity>()
                .eqIfPresent(YdbDeviceZsyEntity::getDeviceId, entity.getDeviceId())
                .eqIfPresent(YdbDeviceZsyEntity::getFlag, entity.getFlag())
                .betweenIfPresent(YdbDeviceZsyEntity::getTime, entity.getDateRange())
                ;
    }


    /**
     * 根据区域id查询设备类别
     *
     * @param areaId 区域id
     * @return
     */
    @Select("SELECT a.area_id,a.device_type,a.device_id,  b.* from ydb_area_device a left join  ydb_device_type b on a.device_id=b.ID where a.area_id = #{areaId}")
    List<YdbDeviceZsyEntity> listAllByAreaId(@Param("areaId") Long areaId);


}
